import type { ManageVO, ManageForm, ManageQuery } from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询项目列表不分页
 * @param params
 * @returns 项目列表
 */
export function surveyListAll(params?: ManageQuery) {
  return requestClient.get<ManageVO[]>('/user/project/list', {
    params,
  });
}

/**
 * 查询项目列表分页
 * @param params
 * @returns 项目列表
 */
export function managePageList(params?: ManageQuery) {
  return requestClient.get<PageResult<ManageVO>>('/user/project/page', {
    params,
  });
}

/**
 * 导出项目列表
 * @param params
 * @returns 项目列表
 */
export function manageExport(params?: ManageQuery) {
  return commonExport('/user/project/export', params ?? {});
}

/**
 * 查询项目详情
 * @param id id
 * @returns 项目详情
 */
// export function manageInfo(id: ID) {
//   return requestClient.get<ManageVO>(`/survey/manage/${id}`);
// }

/**
 * 新增项目
 * @param data
 * @returns void
 */
export function manageAdd(data: ManageForm) {
  return requestClient.postWithMsg<string>('/user/project', data);
}

/**
 * 更新项目
 * @param data
 * @returns void
 */
export function manageUpdate(data: ManageForm) {
  return requestClient.putWithMsg<void>('/user/project', data);
}

/**
 * 删除项目
 * @param id id
 * @returns void
 */
export function manageRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/user/project/${id}`);
}

/**
 * 下架问卷
 * @param id id
 * @returns void
 */
export function stopSurveyStatus(key: ID | IDS) {
  const data = { key };

  return requestClient.postWithMsg<void>(`/user/project/stop`, data);
}

/**
 * 上架问卷
 * @param id id
 * @returns void
 */
export function publishSurveyStatus(key: ID | IDS) {
  const data = { key };

  return requestClient.postWithMsg<void>(`/user/project/publish`, data);
}

/**
 * 问卷校验码
 * @returns code
 */
export function getCheckCode() {
  return requestClient.get<PageResult<ManageVO>>(`/getCheckCode`);
}
